﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DA;

namespace BL.Membership
{
    public class UserData
    {
        public UserData(User user)
        {
            UserId = user.UserId;
            Email = user.EMail;
            ClientId = user.ClientId;
            Permissions = user.GetCalculatedPermissions();
            UserName = user.UserName;
            UserGuid = user.UserGuid;
        }

        public int UserId { get; set; }
        public int ClientId { get; set; }
        public string Email { get; set; }
        public string UserName { get; set; }
        public UserPermission Permissions { get; set; }
        public Guid UserGuid { get; set; }

        public bool IsUserAllowed(IEnumerable<UserPermission> requieredPermissions)
        {
            return IsUserAllowed(requieredPermissions.ToArray());
        }

        public bool IsUserAllowed(params UserPermission[] requieredPermissions)
        {
            return !requieredPermissions.Any() || requieredPermissions.All(x => Permissions.HasFlag(x));
        }
    }
}
